﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Micro.Srv.LogCenter
{
    public class ESIndexHelper
    {
        internal static string[] GetLogIndex(string logPrefix, DateTime beginTime, DateTime endTime)
        {
            if (beginTime > endTime)
                throw new InvalidTimeZoneException("开始时间不能大于结束时间");

            var dic = new Dictionary<string, string>();
            do
            {
                var index = $"{logPrefix}{beginTime.ToString("yyyy.MM.dd")}";
                dic.TryAdd(index, index);
                beginTime = beginTime.AddDays(1);

            } while (beginTime < endTime);

            var endIndex = $"{logPrefix}{endTime.ToString("yyyy.MM.dd")}";
            dic.TryAdd(endIndex, endIndex);

            return dic.Values.ToArray();
        }

        internal static string[] GetOperationLogIndex(DateTime beginTime, DateTime endTime)
        {
            if (beginTime > endTime)
                throw new InvalidTimeZoneException("开始时间不能大于结束时间");

            var dic = new Dictionary<string, string>();
            do
            {
                var index = $"operationlog-{beginTime.ToString("yyyy")}";
                dic.TryAdd(index, index);
                beginTime = beginTime.AddYears(1);

            } while (beginTime < endTime);

            var endIndex = $"operationlog-{endTime.ToString("yyyy")}";
            dic.TryAdd(endIndex, endIndex);

            return dic.Values.ToArray();
        }
    }
}
